function initPage() {
    $.ajax({
        url: "./goPCDD/initPage", //请求的url地址
        xhrFields: {
            withCredentials: true
        },
        async:false,
        dataType: "json", //返回格式为json
        type: "GET", //请求方式
        processData: false, //对表单data数据是否进行序列化
        contentType: false, //dataType设置你收到服务器数据的格式
        headers: {
            'Content-Type': 'application/json'
        },
        beforeSend: function() {
            //请求前的处理
        },
        success: function(data) {
            if(data.status==0){
                // top.location.href = "../../login.html";
                window.location.href="./login.html";
            }else{
            }
        },
        complete: function() {
            //请求完成的处理
        },
        error: function() {}
    });
}

var vm = new Vue({
    el:"#app",
    data(){
        return {
            formItem: {
                CarNo: '',
                CarType: '',
                CarBrand:'',
                CarTypeNo:'',
                CarSBNo:'',
                EngineNo:'',
                RecordDate:'',
                HaveLicenseDate:'',
                RecordNo:'',
                LoadNumber:'',
                InspectionPeriod:'',
                CarStatus:'',
                UseStatus:'',
                Mileage:'',
                HandOrAuto:'',
                CarInfos:'',
            },
            input2:'',
            model1: '',
            model1:false,
            options3: {
                disabledDate (date) {
                    return date;
                }
            },
        }
    },
    created: function () {
        initPage();
    },
    methods:{
        tansuccess (nodesc) {
            this.$Notice.success({
                title: 'Notification title',
                desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
            });
        },
        //手机号验证
        isPoneAvailable(str) {
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        //固定电话验证
        isFixPoneAvailable(str) {
            var myreg=/^0\d{2,3}-\d{7,8}(-\d{1,6})?$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        //身份证号验证
        isCardNoAvailable(str) {
            var myreg=/^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        saveCarInfo() {
            var self = this;
            var jsondata = self.formItem;
            var EditNameStr = parent.$("#uname1").text();
            var EditIDStr = parent.$("#userno1").text();
            jsondata.EditMan = EditNameStr;
            jsondata.EditNo = EditIDStr;

            //校验开始
            if(jsondata.CarNo==''||jsondata.CarNo==null){
                toastr.warning("请输入车牌号");
                return false;
            }
            if(jsondata.CarType==''||jsondata.CarType==null){
                toastr.warning("请输入车辆类型");
                return false;
            }
            if(jsondata.CarBrand==''||jsondata.CarBrand==null){
                toastr.warning("请输入车辆品牌");
                return false;
            }
            if(jsondata.CarTypeNo==''||jsondata.CarTypeNo==null){
                toastr.warning("请输入车辆型号");
                return false;
            }
            if(jsondata.CarSBNo==''||jsondata.CarSBNo==null){
                toastr.warning("请输入车辆识别代号");
                return false;
            }
            if(jsondata.EngineNo==''||jsondata.EngineNo==null){
                toastr.warning("请输入发动机代号");
                return false;
            }

            if(jsondata.RecordDate==''||jsondata.RecordDate==null){
                toastr.warning("请选择注册日期");
                return false;
            }
            var tempRecordDate = new Date(jsondata.RecordDate);
            jsondata.RecordDate = tempRecordDate.toLocaleDateString();

            if(jsondata.HaveLicenseDate==''||jsondata.HaveLicenseDate==null){
                toastr.warning("请选择发证日期");
                return false;
            }
            var tempHaveLicenseDate = new Date(jsondata.HaveLicenseDate);
            jsondata.HaveLicenseDate = tempHaveLicenseDate.toLocaleDateString();

            if(jsondata.RecordNo==''||jsondata.RecordNo==null){
                toastr.warning("请输入档案编号");
                return false;
            }

            if(jsondata.LoadNumber==''||jsondata.LoadNumber==null){
                toastr.warning("请输入核定载人数");
                return false;
            }

            if(jsondata.InspectionPeriod==''||jsondata.InspectionPeriod==null){
                toastr.warning("请选择检验有效期至");
                return false;
            }
            var tempInspectionPeriod = new Date(jsondata.InspectionPeriod);
            jsondata.InspectionPeriod = tempInspectionPeriod.toLocaleDateString();

            if(jsondata.CarStatus==''||jsondata.CarStatus==null){
                toastr.warning("请选择车辆状态");
                return false;
            }

            if(jsondata.UseStatus==''||jsondata.UseStatus==null){
                toastr.warning("请选择使用状态");
                return false;
            }

            if(jsondata.Mileage==''||jsondata.Mileage==null){
                toastr.warning("请输入行驶里程数");
                return false;
            }

            if(jsondata.HandOrAuto==''||jsondata.HandOrAuto==null){
                toastr.warning("请选择手/自动档");
                return false;
            }

            //校验结束
            var data_json = JSON.stringify(jsondata)
            $.ajax({
                url: "./goPCDD/saveCar", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.status=='1'){
                        toastr.success('保存成功');
                        self.formItem.CarNo = "";
                        self.formItem.CarType = "";
                        self.formItem.CarBrand = "";
                        self.formItem.CarTypeNo = "";
                        self.formItem.CarSBNo = "";
                        self.formItem.EngineNo = "";
                        self.formItem.RecordDate = "";
                        self.formItem.HaveLicenseDate = "";
                        self.formItem.RecordNo = "";
                        self.formItem.LoadNumber = "";
                        self.formItem.InspectionPeriod = "";
                        self.formItem.CarStatus = "";
                        self.formItem.UseStatus = "";
                        self.formItem.Mileage = "";
                        self.formItem.HandOrAuto = "";
                        self.formItem.CarInfos = "";
                    }else{
                        toastr.error('保存失败，请重新录入');
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });

        },
        //取消
        goBack(){
            window.location.href = "./car_search.html";
        }
    }
})